Skip to content

fix(opencode): bound codex stream stalls#29446

Open
avilabss wants to merge 1 commit into
anomalyco:devfrom
avilabss:fix/codex-stream-timeouts
Open

fix(opencode): bound codex stream stalls#29446
avilabss wants to merge 1 commit into
anomalyco:devfrom
avilabss:fix/codex-stream-timeouts

Conversation

@avilabss
Copy link
Copy Markdown

@avilabss avilabss commented May 26, 2026

Issue for this PR

Closes #29129

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

ChatGPT/Codex OAuth streams can currently sit forever if the upstream request stalls before producing a response, or if an SSE stream stops producing chunks. That leaves the session busy with no visible error.

This PR adds bounded timeouts for that path and lets the existing retry flow recover from those timeout errors. It also avoids relying on AbortSignal.timeout() for provider request timeouts, since the current wrapper already disables Bun's fetch timeout.

How did you verify your code works?

  • npx --yes bun typecheck from packages/opencode
  • npx --yes bun test test/session/retry.test.ts from packages/opencode

Screenshots / recordings

N/A, no UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels May 26, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@avilabss avilabss force-pushed the fix/codex-stream-timeouts branch from 77ae84c to 04b5394 Compare May 26, 2026 19:27
@avilabss avilabss force-pushed the fix/codex-stream-timeouts branch from 04b5394 to 8a781ca Compare May 26, 2026 19:31
Copy link
Copy Markdown

@niStee niStee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! We just ran into this exact infinite socket hang today, so looking forward to the merge.

return response.json()
}

function timeoutController(ms: number) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, I was looking at some of the other plugins (like github-copilot, etc.) and noticed they also make custom fetch calls during their specific OAuth or authentication flows.

Since these custom authentication fetches aren't wrapped by the new main provider timeout, are they still vulnerable to infinite socket hangs if their respective APIs stall during login? Should we consider abstracting this timeoutController logic so it can be easily applied to all custom provider token/auth fetches?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@niStee Good catch. I think you’re right.

The new provider timeout protects the actual provider request path, including custom fetch once it’s invoked by the wrapper, but direct auth/token fetch calls inside plugins are outside that protection. So a stalled OAuth/token endpoint can still hang unless that specific call receives/uses a signal or creates its own timeout.

I’d prefer not to broaden this PR too much beyond the Codex timeout bug, but a shared helper for bounded auth fetches makes sense. I can either extract that helper here, or keep this focused and follow up with a small PR applying it across the custom auth flows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAI stream intermittently freezes in working state with high CPU and idle HTTPS socket

2 participants